﻿@model Busconeitor.Web.Models.QueryModel
@{
    ViewBag.Title = "Search";
}
@using (Html.BeginForm("Search", "Home", FormMethod.Post))
{
    <div class="container theme-showcase">
        <!-- Main jumbotron for a primary marketing message or call to action -->
        <div class="jumbotron">
            <h2>
                Search Engine
            </h2>
            <div class="form-group">
                <div class="input-group">
                    @Html.TextBox("query", null, new { id = "query", @class = "form-control", placeholder = "Write something here" })
                    <span class="input-group-btn">
                        <input class="btn btn-success" value="Search" type="submit" />
                    </span>
                </div>
            </div>
        </div>
    </div>
    <div class="container">
        <div class="page-header">
            <h2>
                Search Results
            </h2>

            @if (Model.TotalResults > 0)
            {
                <p class="text-warning">
                    <strong>for</strong> "@Model.Query" | <strong>total results</strong> "@Model.TotalResults" | <strong>search time</strong> "@Model.SearchTime"
                </p>
            }
            else
            {
                <p class="text-danger">
                    <strong>for</strong> "@Model.Query" | <strong>total results</strong> "@Model.TotalResults"
                </p>
            }

        </div>

        @if (Model.TotalResults > 0)
        {
            <div id="resultContainer">
                @Html.Partial("_Results", Model)
            </div>
        }
    </div>
    <script type="text/javascript">
        var paginaActual = 1;
        var ultimaPagina = 5;
        var query = "noel";

        $(document).ready(
            function () {
                $('.prevPage').click(
                    function () {
                        if ($('#prev').hasClass('disabled')) {
                            return;
                        } else {
                            var actual = $('ul li.active').removeClass('active');
                            $(actual).prev().addClass('active');
                        }

                        $('#prev, #next').removeClass('disabled');

                        if (paginaActual - 1 == 1) {
                            $('#prev').addClass('disabled');
                        }

                        paginaActual--;
                        GetPage(paginaActual);
                    }
                );

                $('.numPage').click(
                    function () {
                        var newPage = $(this).html();
                        paginaActual = newPage;
                        GetPage(paginaActual);
                        $('ul li.active').removeClass('active');
                        $(this).parent().addClass('active');
                    }
                );

                $('.nextPage').click(
                    function () {
                        if ($('#next').hasClass('disabled')) {
                            return;
                        } else {
                            var actual = $('ul li.active').removeClass('active');
                            $(actual).next().addClass('active');
                        }

                        $('#prev, #next').removeClass('disabled');

                        if (paginaActual + 1 == ultimaPagina) {
                            $('#next').addClass('disabled');
                        }

                        paginaActual++;
                        GetPage(paginaActual);
                    }
                );
            }
        );
    </script>
}
